package io.lvdaxian.handwriting.jvm;

/**
 * @author lihaohao
 * @descirption 栈上分配 测试  -XX:-DoEscapeAnalysis 添加该参数后 关闭逃逸分析。 直接堆上分析
 */
public class EscapeAnalysisTestStr {
    public static void main(String[] args) throws InterruptedException {
        long startTime = System.currentTimeMillis();

        // 申请 内存
        for (int i = 0; i < 50000000; i++) {
            allocate();
        }

        System.out.println((System.currentTimeMillis() - startTime) + "ms");
        Thread.sleep(600000);
    }

    static void allocate() {
        MyObject myObject = new MyObject(2020, 2020.6, "lihaohao");
    }

    static class MyObject {
        int a;
        double b;
        String name;

        MyObject(int a, double b, String name) {
            this.a = a;
            this.b = b;
            this.name = name;
        }
    }
}
